#include "chapter_practice_10_2.h"
#include "chapter_practice_10_8.h"
#include <iostream>



Person_practice_10_2::Person_practice_10_2(const string & ln, const char * fn )	//#2
{
	lname = ln;
	strcpy(fname, fn);
}

void Person_practice_10_2::Show() const
{
	cout << fname << " " << lname<<endl;
}

void Person_practice_10_2::FormalShow() const
{
	cout << lname << "," << fname << endl;
}

MyList::MyList()
{
	top = 0;
	bottom = 0;
	count = 0;
}

bool MyList::isfull() const
{
    return	count == MAX;
}

bool MyList::isempty() const
{
	return	count == 0;
}

bool MyList::push(const Item & item)
{
	if (!isfull())
	{
		if (top < MAX)
			items[top++] = item;
		else
		{
			top = top % MAX;
			items[top++] = item;
		}
		count++;
		return true;
	}
	else
	{
		return false;
	}
}

bool MyList::pop(Item & item)
{
	if (isempty())
	{
		return false;
	}
	else
	{
		if (bottom < MAX)
			item = items[bottom++];
		else
		{
			bottom = bottom%MAX;
			item = items[bottom++];
		}
		count--;
		return true;
	}
}

void MyList::visit(void(*pf)(Item &))
{
	for (int i = 0; i < count; i++)
		(*pf)(items[i]);
}

